Skip to contents

So far, we’ve demonstrated using EMODnetWFS to request complete layers.

However, WFS services allows us to be selective with what features are returned from the EMODnet servers. For example: using CQL filters, we can send a query including a filtering clause that will be executed on the server and return only the subset of the information we request. This can make queries a lot faster and reduce the need for filtering data after download.

For example, let’s consider the case where we want to include the territorial sea boundaries in a habitat map. One way to approach this would be to download the full layer containing all the European maritime boundaries from the human activities service and then filter the sf object returned for features representing Territorial Seas.

A more efficient approach would be to use a filter and request only the features representing Territorial Seas from the server. Let’s have a look at how to do that.

CQL & ECQL Query languages.

CQL (Common Query Language) is a plain-text language created for the OGC Catalog specification. GeoServer has adapted it to be an easy-to-use filtering mechanism. GeoServer actually implements a more powerful extension called ECQL (Extended CQL), which allows expressing the full range of filters that OGC Filter 1.1 can encode. ECQL is accepted in many places in GeoServer

GeoServer supports the use of both CQL and ECQL in WFS requests and whenever the documentation refers to CQL, ECQL syntax can be used as well.

Inintialise EMODnet WFS client

First, let’s load the library and start a new WFS client with emodnet_init_wfs_client.

wfs_ha <- emodnet_init_wfs_client(service = "human_activities")
#> Loading ISO 19139 XML schemas...
#> Loading ISO 19115 codelists...
#> Loading IANA mime types...
#> No encoding supplied: defaulting to UTF-8.
#>  WFS client created succesfully
#>  Service: 'https://ows.emodnet-humanactivities.eu/wfs'
#>  Version: '2.0.0'

Inspecting attributes

To develop filters, we first need information about the attributes we can filter on. For example, we might want to know the data type and range or distribution of values of each attributes of a given layer.

Layer attribute names

To start, you might want to know the names of a layer’s attributes.

layer_attributes_get_names(wfs_ha, layer = "maritimebnds")
#>  [1] "objectid"   "mblszotpid" "localid"    "sitename"   "legalfound"
#>  [6] "legalfou_1" "country"    "nationalle" "nutscode"   "mblsds_mbl"
#> [11] "shape_leng" "the_geom"

All functions can also be used by providing a service name instead of a wfs object.

layer_attributes_get_names(service = "human_activities", layer = "maritimebnds")
#>  WFS client created succesfully
#>  Service: 'https://ows.emodnet-humanactivities.eu/wfs'
#>  Version: '2.0.0'
#>  [1] "objectid"   "mblszotpid" "localid"    "sitename"   "legalfound"
#>  [6] "legalfou_1" "country"    "nationalle" "nutscode"   "mblsds_mbl"
#> [11] "shape_leng" "the_geom"

Layer attribute descriptions

The type of filtering you might want to apply will depend on the data type of each attribute.

You can inspect attribute descriptions (metadata) for a given layer with layer_attribute_descriptions().

layer_attribute_descriptions(wfs_ha, layer = "maritimebnds")
#>          name      type minOccurs maxOccurs nillable
#> 1    objectid   numeric         0         1     TRUE
#> 2  mblszotpid   integer         0         1     TRUE
#> 3     localid   numeric         0         1     TRUE
#> 4    sitename character         0         1     TRUE
#> 5  legalfound      Date         0         1     TRUE
#> 6  legalfou_1 character         0         1     TRUE
#> 7     country character         0         1     TRUE
#> 8  nationalle character         0         1     TRUE
#> 9    nutscode character         0         1     TRUE
#> 10 mblsds_mbl character         0         1     TRUE
#> 11 shape_leng    double         0         1     TRUE
#> 12   the_geom  geometry         0         1     TRUE

Layer attribute summaries

You can get summaries of the values of each attribute with layer_attributes_summarise(). This function basically runs summary() on the attribute columns of the layer.

layer_attributes_summarise(wfs_ha, layer = "maritimebnds")
#>     gml_id             objectid        mblszotpid      localid       
#>  Length:1048        Min.   :   1.0   Min.   :0.00   Min.   :    0.0  
#>  Class :character   1st Qu.: 262.8   1st Qu.:0.00   1st Qu.:  346.8  
#>  Mode  :character   Median : 524.5   Median :1.00   Median : 1745.5  
#>                     Mean   : 524.5   Mean   :1.73   Mean   : 9188.8  
#>                     3rd Qu.: 786.2   3rd Qu.:3.00   3rd Qu.: 3751.2  
#>                     Max.   :1048.0   Max.   :7.00   Max.   :62595.0  
#>                                                                      
#>    sitename           legalfound          legalfou_1          country         
#>  Length:1048        Min.   :1932-01-30   Length:1048        Length:1048       
#>  Class :character   1st Qu.:1984-11-09   Class :character   Class :character  
#>  Mode  :character   Median :2004-12-06   Mode  :character   Mode  :character  
#>                     Mean   :1999-11-21                                        
#>                     3rd Qu.:2012-12-26                                        
#>                     Max.   :2019-09-29                                        
#>                     NA's   :221                                               
#>   nationalle          nutscode          mblsds_mbl          shape_leng       
#>  Length:1048        Length:1048        Length:1048        Min.   :   0.0000  
#>  Class :character   Class :character   Class :character   1st Qu.:   0.0829  
#>  Mode  :character   Mode  :character   Mode  :character   Median :   0.5562  
#>                                                           Mean   :  13.3026  
#>                                                           3rd Qu.:   4.1102  
#>                                                           Max.   :1804.3286  
#> 

Inspecting individual layer attributes

You can also inspect individual attributes which, in the case of categorical variables, can give more detailed information on the names and distribution of categories.

layer_attribute_inspect(wfs_ha, layer = "maritimebnds", attribute = "sitename")
#>                                                         .   n    percent
#>                                                  Baseline 486 0.46374046
#>                                   Contiguous zone (24 nm)  65 0.06202290
#>                                         Continental Shelf  78 0.07442748
#>                          Delimitation line between states 212 0.20229008
#>                      Exclusive Economic Zone (200 nm) EEZ  68 0.06488550
#>        Exclusive Economic Zone (200 nm) EEZ - Median Line  23 0.02194656
#>  Exclusive Economic Zone (200 nm) EEZ - Overlapping claim  14 0.01335878
#>                                           Internal waters  38 0.03625954
#>                                     Territory sea (12 nm)  64 0.06106870

Layer attributes table

Finally, to enable full inspection and custom processing of attribute data, you can download the full set of attributes as a data.frame, excluding the geometry column. As the geometries are usually the largest column, this is much faster than downloading the full layer and can be useful in developing attribute filtering rules.

attr_tbl <- layer_attributes_tbl(wfs_ha, layer = "maritimebnds")

attr_tbl
#> # A tibble: 1,048 × 12
#>    gml_id     objectid mblszotpid localid sitename legalfound legalfou_1 country
#>    <chr>         <dbl>      <int>   <dbl> <chr>    <date>     <chr>      <chr>  
#>  1 maritimeb…        1          7   49469 Interna… NA         NA         Germany
#>  2 maritimeb…        2          7   49471 Interna… NA         NA         Bulgar…
#>  3 maritimeb…        3          7   49472 Interna… NA         NA         Croatia
#>  4 maritimeb…        4          7   49473 Interna… NA         NA         Denmark
#>  5 maritimeb…        5          7   49474 Interna… NA         NA         Estonia
#>  6 maritimeb…        6          7   49475 Interna… NA         NA         Finland
#>  7 maritimeb…        7          7   49476 Interna… NA         NA         France 
#>  8 maritimeb…        8          7   49478 Interna… NA         NA         Ireland
#>  9 maritimeb…        9          7   49479 Interna… NA         NA         Italy  
#> 10 maritimeb…       10          7   49480 Interna… NA         NA         Latvia 
#> # … with 1,038 more rows, and 4 more variables: nationalle <chr>,
#> #   nutscode <chr>, mblsds_mbl <chr>, shape_leng <dbl>
skimr::skim(attr_tbl)
Data summary
Name attr_tbl
Number of rows 1048
Number of columns 12
_______________________
Column type frequency:
character 7
Date 1
numeric 4
________________________
Group variables None

Variable type: character

skim_variable n_missing complete_rate min max empty n_unique whitespace
gml_id 0 1.00 14 17 0 1048 0
sitename 0 1.00 8 56 0 9 0
legalfou_1 398 0.62 8 116 0 134 0
country 0 1.00 5 49 0 168 0
nationalle 379 0.64 9 25 0 6 0
nutscode 0 1.00 2 10 0 169 0
mblsds_mbl 0 1.00 13 254 0 150 0

Variable type: Date

skim_variable n_missing complete_rate min max median n_unique
legalfound 221 0.79 1932-01-30 2019-09-29 2004-12-06 157

Variable type: numeric

skim_variable n_missing complete_rate mean sd p0 p25 p50 p75 p100 hist
objectid 0 1 524.50 302.68 1 262.75 524.50 786.25 1048.00 ▇▇▇▇▇
mblszotpid 0 1 1.73 1.95 0 0.00 1.00 3.00 7.00 ▇▂▅▁▁
localid 0 1 9188.80 17590.32 0 346.75 1745.50 3751.25 62595.00 ▇▁▁▂▁
shape_leng 0 1 13.30 85.08 0 0.08 0.56 4.11 1804.33 ▇▁▁▁▁

Filtering by attributes

Filtering categorical attributes values using text comparisons

Once we know the values of a categorical attribute of a layer, we can use them to filter the features returned from our query. For example, let’s say we are only interested in the territorial sea boundaries that extend to 12 nautical miles. From our previous interrogation of the attributes associated with the maritimebnds layer, we have seen that the attribute sitename contains categories of type of boundary for each feature (row) and the value Territory sea (12 nm) indicates a territorial sea maritime boundary.

We can use the name of the attribute and the value we require to construct our eqcl filter and pass it to our request using the cql_filter argument.

emodnet_get_layers(wfs_ha, layers = "maritimebnds", 
                   cql_filter = "sitename = 'Territory sea (12 nm)'" )
#> $maritimebnds
#> Simple feature collection with 64 features and 12 fields
#> Geometry type: MULTICURVE
#> Dimension:     XY
#> Bounding box:  xmin: -178.3897 ymin: -50.21866 xmax: 169.1762 ymax: 83.8746
#> Geodetic CRS:  WGS 84
#> First 10 features:
#>             gml_id objectid mblszotpid localid              sitename legalfound
#> 1  maritimebnds.49       49          1   49024 Territory sea (12 nm)       <NA>
#> 2  maritimebnds.58       58          1   49064 Territory sea (12 nm)       <NA>
#> 3  maritimebnds.59       59          1   49065 Territory sea (12 nm)       <NA>
#> 4  maritimebnds.60       60          1   49066 Territory sea (12 nm)       <NA>
#> 5  maritimebnds.61       61          1   49087 Territory sea (12 nm)       <NA>
#> 6  maritimebnds.62       62          1   49099 Territory sea (12 nm)       <NA>
#> 7  maritimebnds.54       54          1   49034 Territory sea (12 nm)       <NA>
#> 8  maritimebnds.55       55          1   49036 Territory sea (12 nm)       <NA>
#> 9  maritimebnds.56       56          1   49042 Territory sea (12 nm)       <NA>
#> 10 maritimebnds.57       57          1   49063 Territory sea (12 nm)       <NA>
#>    legalfou_1        country nationalle nutscode               mblsds_mbl
#> 1        <NA>         Latvia       <NA>       LV In www.marineregions.org
#> 2        <NA>         France       <NA>       FR In www.marineregions.org
#> 3        <NA>         France       <NA>       FR In www.marineregions.org
#> 4        <NA>         France       <NA>       FR In www.marineregions.org
#> 5        <NA>          Spain       <NA>       ES In www.marineregions.org
#> 6        <NA>         Cyprus       <NA>       CY In www.marineregions.org
#> 7        <NA>         Sweden       <NA>       SE In www.marineregions.org
#> 8        <NA> United Kingdom       <NA>       UK In www.marineregions.org
#> 9        <NA>         France       <NA>       FR In www.marineregions.org
#> 10       <NA>         France       <NA>       FR In www.marineregions.org
#>    shape_leng                       the_geom
#> 1   12.005746 MULTICURVE (LINESTRING (23....
#> 2    1.949563 MULTICURVE (LINESTRING (42....
#> 3    2.072975 MULTICURVE (LINESTRING (39....
#> 4    1.837879 MULTICURVE (LINESTRING (40....
#> 5   27.878496 MULTICURVE (LINESTRING (-17...
#> 6   13.642806 MULTICURVE (LINESTRING (34....
#> 7   68.013014 MULTICURVE (LINESTRING (19....
#> 8  141.545470 MULTICURVE (LINESTRING (-13...
#> 9   70.017156 MULTICURVE (LINESTRING (169...
#> 10   5.116398 MULTICURVE (LINESTRING (55....

The above shows the most basic text comparisons we can make use the equality operator =. If we want to match more than one value, we can use the operator IN instead and provide a list of values to compare to. For example, to request both Territorial (12 nm) and Contiguous zone (24 nm) boundaries, we could use the following filter:

emodnet_get_layers(wfs_ha, layers = "maritimebnds", 
                   cql_filter = "sitename IN ('Territory sea (12 nm)', 'Contiguous zone (24 nm)')" )
#> $maritimebnds
#> Simple feature collection with 129 features and 12 fields
#> Geometry type: MULTICURVE
#> Dimension:     XY
#> Bounding box:  xmin: -178.5958 ymin: -50.41859 xmax: 169.3925 ymax: 84.0737
#> Geodetic CRS:  WGS 84
#> First 10 features:
#>             gml_id objectid mblszotpid localid              sitename legalfound
#> 1  maritimebnds.49       49          1   49024 Territory sea (12 nm)       <NA>
#> 2  maritimebnds.58       58          1   49064 Territory sea (12 nm)       <NA>
#> 3  maritimebnds.59       59          1   49065 Territory sea (12 nm)       <NA>
#> 4  maritimebnds.60       60          1   49066 Territory sea (12 nm)       <NA>
#> 5  maritimebnds.61       61          1   49087 Territory sea (12 nm)       <NA>
#> 6  maritimebnds.62       62          1   49099 Territory sea (12 nm)       <NA>
#> 7  maritimebnds.54       54          1   49034 Territory sea (12 nm)       <NA>
#> 8  maritimebnds.55       55          1   49036 Territory sea (12 nm)       <NA>
#> 9  maritimebnds.56       56          1   49042 Territory sea (12 nm)       <NA>
#> 10 maritimebnds.57       57          1   49063 Territory sea (12 nm)       <NA>
#>    legalfou_1        country nationalle nutscode               mblsds_mbl
#> 1        <NA>         Latvia       <NA>       LV In www.marineregions.org
#> 2        <NA>         France       <NA>       FR In www.marineregions.org
#> 3        <NA>         France       <NA>       FR In www.marineregions.org
#> 4        <NA>         France       <NA>       FR In www.marineregions.org
#> 5        <NA>          Spain       <NA>       ES In www.marineregions.org
#> 6        <NA>         Cyprus       <NA>       CY In www.marineregions.org
#> 7        <NA>         Sweden       <NA>       SE In www.marineregions.org
#> 8        <NA> United Kingdom       <NA>       UK In www.marineregions.org
#> 9        <NA>         France       <NA>       FR In www.marineregions.org
#> 10       <NA>         France       <NA>       FR In www.marineregions.org
#>    shape_leng                       the_geom
#> 1   12.005746 MULTICURVE (LINESTRING (23....
#> 2    1.949563 MULTICURVE (LINESTRING (42....
#> 3    2.072975 MULTICURVE (LINESTRING (39....
#> 4    1.837879 MULTICURVE (LINESTRING (40....
#> 5   27.878496 MULTICURVE (LINESTRING (-17...
#> 6   13.642806 MULTICURVE (LINESTRING (34....
#> 7   68.013014 MULTICURVE (LINESTRING (19....
#> 8  141.545470 MULTICURVE (LINESTRING (-13...
#> 9   70.017156 MULTICURVE (LINESTRING (169...
#> 10   5.116398 MULTICURVE (LINESTRING (55....

Other text comparisons include text pattern matching using operator LIKE. For example, to request maritime boundaries for countries starting with an F, we can use the following filter:

emodnet_get_layers(wfs = wfs_ha, layers = "maritimebnds",
                       cql_filter = "country LIKE 'F%'",
                       reduce_layers = TRUE )
#> Simple feature collection with 348 features and 12 fields
#> Geometry type: MULTICURVE
#> Dimension:     XY
#> Bounding box:  xmin: -180 ymin: -53.17863 xmax: 180 ymax: 66.77516
#> Geodetic CRS:  WGS 84
#> First 10 features:
#>             gml_id objectid mblszotpid localid              sitename legalfound
#> 1   maritimebnds.6        6          7   49475       Internal waters       <NA>
#> 2   maritimebnds.7        7          7   49476       Internal waters       <NA>
#> 3  maritimebnds.17       17          7   49489       Internal waters       <NA>
#> 4  maritimebnds.20       20          7   49510       Internal waters       <NA>
#> 5  maritimebnds.21       21          7   49511       Internal waters       <NA>
#> 6  maritimebnds.24       24          7   49526       Internal waters       <NA>
#> 7  maritimebnds.25       25          7   49529       Internal waters       <NA>
#> 8  maritimebnds.26       26          7   49531       Internal waters       <NA>
#> 9  maritimebnds.27       27          7   49554       Internal waters       <NA>
#> 10 maritimebnds.58       58          1   49064 Territory sea (12 nm)       <NA>
#>    legalfou_1 country nationalle nutscode               mblsds_mbl  shape_leng
#> 1        <NA> Finland       <NA>       FI In www.marineregions.org 398.7539953
#> 2        <NA>  France       <NA>       FR In www.marineregions.org  86.6331459
#> 3        <NA>  France       <NA>       FR In www.marineregions.org 135.5138148
#> 4        <NA>  France       <NA>       FR In www.marineregions.org   0.1318911
#> 5        <NA>  France       <NA>       FR In www.marineregions.org  38.2607730
#> 6        <NA>  France       <NA>       FR In www.marineregions.org  83.0109917
#> 7        <NA>  France       <NA>       FR In www.marineregions.org   1.7084591
#> 8        <NA>  France       <NA>       FR In www.marineregions.org   6.2202438
#> 9        <NA>  France       <NA>       FR In www.marineregions.org   0.8742504
#> 10       <NA>  France       <NA>       FR In www.marineregions.org   1.9495627
#>                          the_geom
#> 1  MULTICURVE (LINESTRING (27....
#> 2  MULTICURVE (LINESTRING (9.4...
#> 3  MULTICURVE (LINESTRING (166...
#> 4  MULTICURVE (LINESTRING (77....
#> 5  MULTICURVE (LINESTRING (68....
#> 6  MULTICURVE (LINESTRING (-14...
#> 7  MULTICURVE (LINESTRING (-17...
#> 8  MULTICURVE (LINESTRING (-52...
#> 9  MULTICURVE (LINESTRING (-56...
#> 10 MULTICURVE (LINESTRING (42....

CQL/ECQL filters can also include any of the filter functions available in GeoServer, including multiple string functions which greatly increases the power of CQL expressions.

For example, we can request countries that contain l anywhere, including the first letter. To make the request case independent, we can turn country names to lowercase and then use a like comparison to a lowercase l:

emodnet_get_layers(wfs = wfs_ha, layers = "maritimebnds",
                       cql_filter = "strToLowerCase(country) LIKE '%l%'",
                       reduce_layers = TRUE )
#> Simple feature collection with 304 features and 12 fields
#> Geometry type: MULTICURVE
#> Dimension:     XY
#> Bounding box:  xmin: -180 ymin: -53.23528 xmax: 180 ymax: 69.58333
#> Geodetic CRS:  WGS 84
#> First 10 features:
#>             gml_id objectid mblszotpid localid              sitename legalfound
#> 1   maritimebnds.2        2          7   49471       Internal waters       <NA>
#> 2   maritimebnds.6        6          7   49475       Internal waters       <NA>
#> 3   maritimebnds.8        8          7   49478       Internal waters       <NA>
#> 4   maritimebnds.9        9          7   49479       Internal waters       <NA>
#> 5  maritimebnds.10       10          7   49480       Internal waters       <NA>
#> 6  maritimebnds.11       11          7   49481       Internal waters       <NA>
#> 7  maritimebnds.13       13          7   49483       Internal waters       <NA>
#> 8  maritimebnds.49       49          1   49024 Territory sea (12 nm)       <NA>
#> 9  maritimebnds.12       12          7   49482       Internal waters       <NA>
#> 10 maritimebnds.32       32          7   49562       Internal waters       <NA>
#>    legalfou_1   country nationalle nutscode               mblsds_mbl shape_leng
#> 1        <NA>  Bulgaria       <NA>       BG In www.marineregions.org   4.544187
#> 2        <NA>   Finland       <NA>       FI In www.marineregions.org 398.753995
#> 3        <NA>   Ireland       <NA>       IE In www.marineregions.org  86.831518
#> 4        <NA>     Italy       <NA>       IT In www.marineregions.org 107.881909
#> 5        <NA>    Latvia       <NA>       LV In www.marineregions.org  15.633767
#> 6        <NA> Lithuania       <NA>       LT In www.marineregions.org   4.944433
#> 7        <NA>    Poland       <NA>       PL In www.marineregions.org  12.826955
#> 8        <NA>    Latvia       <NA>       LV In www.marineregions.org  12.005746
#> 9        <NA>     Malta       <NA>       MT In www.marineregions.org   2.775480
#> 10       <NA>  Portugal       <NA>       PT In www.marineregions.org  10.824344
#>                          the_geom
#> 1  MULTICURVE (LINESTRING (28....
#> 2  MULTICURVE (LINESTRING (27....
#> 3  MULTICURVE (LINESTRING (-7....
#> 4  MULTICURVE (LINESTRING (14....
#> 5  MULTICURVE (LINESTRING (24....
#> 6  MULTICURVE (LINESTRING (21....
#> 7  MULTICURVE (LINESTRING (18....
#> 8  MULTICURVE (LINESTRING (23....
#> 9  MULTICURVE (LINESTRING (14....
#> 10 MULTICURVE (LINESTRING (-31...

Filtering numeric variables

A number of additional comparison operators, such as =, <>, >, >=, <, <= , arithmetic operators +, -, *, / as well as comparison and math functions can be used for filtering numeric variables.

This time we’ll use the 1m seabed substrate layer from the Geology Seabed Substrate maps endpoint and filter our requests according to the shape length of each feature.

Again, we start by initialising a new WFS client:

wfs_gs <- emodnet_init_wfs_client(service = "geology_seabed_substrate_maps")
#>  WFS client created succesfully
#>  Service: 'https://drive.emodnet-geology.eu/geoserver/gtk/wfs'
#>  Version: '2.0.0'

We can inspect again use some of our interrogative functions to get information on layer attributes.

layer_attributes_get_names(wfs_gs, layer = "seabed_substrate_1m")
#>  [1] "id"                  "geom"                "objectid"           
#>  [4] "code"                "country"             "data_holder"        
#>  [7] "contact"             "scale"               "original_scale"     
#> [10] "original_grain_size" "references"          "comments"           
#> [13] "reclassification"    "method"              "sample_number"      
#> [16] "original_substrate"  "relation"            "folk_16cl"          
#> [19] "folk_16cl_txt"       "folk_7cl"            "folk_7cl_txt"       
#> [22] "folk_5cl"            "folk_5cl_txt"        "surface_feature"    
#> [25] "conf_rs"             "conf_s"              "conf_d"             
#> [28] "conf_tot"            "shape_length"        "shape_area"

layer_attribute_inspect(wfs_gs, layer = "seabed_substrate_1m", attribute = "shape_length")
#>      Min.   1st Qu.    Median      Mean   3rd Qu.      Max. 
#>   0.00000   0.02067   0.08611   0.55317   0.24652 294.92762

We can see that values range between 0 and ~295 with a mean of ~0.55.

Let’s say we are interested in values greater than 5. We can use the operator > to create our filter:

emodnet_get_layers(wfs = wfs_gs, layers = "seabed_substrate_1m",
                       cql_filter = "shape_length > 5",
                       reduce_layers = TRUE )
#> Simple feature collection with 597 features and 30 fields
#> Geometry type: MULTISURFACE
#> Dimension:     XY
#> Bounding box:  xmin: 1330843 ymin: 479670.8 xmax: 7657336 ymax: 6622268
#> Projected CRS: ETRS89-extended / LCC Europe
#> First 10 features:
#>                       gml_id    id objectid   code       country  data_holder
#> 1     seabed_substrate_1m.46    46       46 BE-004       Belgium        RBINS
#> 2     seabed_substrate_1m.48    48       48 BG-001      Bulgaria IO-BAS, MOEW
#> 3     seabed_substrate_1m.60    60       60 BG-001      Bulgaria IO-BAS, MOEW
#> 4     seabed_substrate_1m.91    91       91 BG-001      Bulgaria IO-BAS, MOEW
#> 5  seabed_substrate_1m.14260 14260    14260  GB001 Great Britain          BGS
#> 6  seabed_substrate_1m.16404 16404    16404  HR003       Croatia      HGI-HHI
#> 7    seabed_substrate_1m.310   310      310 DE-001       Germany         GPDN
#> 8    seabed_substrate_1m.476   476      476 DE-001       Germany         GPDN
#> 9    seabed_substrate_1m.496   496      496 DE-001       Germany         GPDN
#> 10   seabed_substrate_1m.553   553      553 DE-001       Germany         GPDN
#>                               contact   scale original_scale
#> 1  vera.vanlancker@naturalsciences.be 1000000              0
#> 2                      geos@io-bas.bg 1000000              0
#> 3                      geos@io-bas.bg 1000000              0
#> 4                      geos@io-bas.bg 1000000              0
#> 5                   rcooper@bgs.ac.uk 1000000              0
#> 6                ranko.crmaric@hhi.hr 1000000              0
#> 7               manfred.zeiler@bsh.de 1000000              0
#> 8               manfred.zeiler@bsh.de 1000000              0
#> 9               manfred.zeiler@bsh.de 1000000              0
#> 10              manfred.zeiler@bsh.de 1000000              0
#>    original_grain_size
#> 1                Folk5
#> 2           BNS-676.85
#> 3           BNS-676.85
#> 4           BNS-676.85
#> 5            Folk - 16
#> 6         Folk class 7
#> 7                 Folk
#> 8                 Folk
#> 9                 Folk
#> 10             FOLK_15
#>                                                                                                    references
#> 1          Van Lancker, V. (2009). SediCURVE@SEA: a multiparameter sedimentdatabase in support of EIA at sea.
#> 2  Kojuharov et al., 2009, Geological map of Seabed sediments of Bulgarian EEZ in scale 1:500000, Sofia, MOEW
#> 3  Kojuharov et al., 2009, Geological map of Seabed sediments of Bulgarian EEZ in scale 1:500000, Sofia, MOEW
#> 4  Kojuharov et al., 2009, Geological map of Seabed sediments of Bulgarian EEZ in scale 1:500000, Sofia, MOEW
#> 5                                                                                               DIGSBS250k_v3
#> 6                                                                                                            
#> 7                                                Naumann M,  Schwarz C, Fritz J, Zeiler M (2013), www.gpdn.de
#> 8                                                Naumann M,  Schwarz C, Fritz J, Zeiler M (2013), www.gpdn.de
#> 9                                                Naumann M,  Schwarz C, Fritz J, Zeiler M (2013), www.gpdn.de
#> 10                                                    Federal Maritime And Hydrographic Agency (BSH), Germany
#>                                                                                                                             comments
#> 1                                                                                                                           1M scale
#> 2                                                                                                                        Public data
#> 3                                                                                                                        Public data
#> 4                                                                                                                        Public data
#> 5                                                               Generalized from 250k scale to 1 M by GTK June 2016/EMODnet Geology.
#> 6                                                                                                                                   
#> 7  Generalized from 250k scale to 1 M by GTK June 2016/EMODnet Geology. Original map generalized following the EMODnet 2 guidelines.
#> 8  Generalized from 250k scale to 1 M by GTK June 2016/EMODnet Geology. Original map generalized following the EMODnet 2 guidelines.
#> 9  Generalized from 250k scale to 1 M by GTK June 2016/EMODnet Geology. Original map generalized following the EMODnet 2 guidelines.
#> 10 Generalized from 250k scale to 1 M by GTK June 2016/EMODnet Geology. Original map generalized following the EMODnet 2 guidelines.
#>    reclassification method sample_number
#> 1                 1      1          4461
#> 2                 2      4             0
#> 3                 2      4             0
#> 4                 2      4             0
#> 5                 3      2             0
#> 6                 1      4             0
#> 7                 0      0             0
#> 8                 0      0             0
#> 9                 0      0             0
#> 10                1      1             0
#>                                    original_substrate relation folk_16cl
#> 1                                                            1         6
#> 2                   Local Lithostratigraphyc unit A-D        5         6
#> 3  Local Lithostratigraphyc unit Ia-carbonate-biogeni        5         6
#> 4                   Local Lithostratigraphyc unit K-H        5         6
#> 5                                                            0         6
#> 6                                                 Mud        2         6
#> 7                                                            0         6
#> 8                                                            0         6
#> 9                                                            0         6
#> 10                                                           0         6
#>               folk_16cl_txt folk_7cl   folk_7cl_txt folk_5cl
#> 1  6. No data at this level        2        2. Sand        2
#> 2  6. No data at this level       11       11. Mud         1
#> 3  6. No data at this level       11       11. Mud         1
#> 4  6. No data at this level       11       11. Mud         1
#> 5  6. No data at this level        2        2. Sand        2
#> 6  6. No data at this level       11       11. Mud         1
#> 7  6. No data at this level        2        2. Sand        2
#> 8  6. No data at this level       13 13. muddy Sand        1
#> 9  6. No data at this level       13 13. muddy Sand        1
#> 10 6. No data at this level        2        2. Sand        2
#>            folk_5cl_txt surface_feature conf_rs conf_s conf_d conf_tot
#> 1              2. Sand                       NA     NA     NA       NA
#> 2  1. Mud to muddy Sand                      NA     NA     NA       NA
#> 3  1. Mud to muddy Sand                      NA     NA     NA       NA
#> 4  1. Mud to muddy Sand                      NA     NA     NA       NA
#> 5              2. Sand                       NA     NA     NA       NA
#> 6  1. Mud to muddy Sand                      NA     NA     NA       NA
#> 7              2. Sand                       NA     NA     NA       NA
#> 8  1. Mud to muddy Sand                      NA     NA     NA       NA
#> 9  1. Mud to muddy Sand                      NA     NA     NA       NA
#> 10             2. Sand                       NA     NA     NA       NA
#>    shape_length shape_area                           geom
#> 1      7.550753 0.31929437 MULTISURFACE (POLYGON ((350...
#> 2      7.378181 0.56731575 MULTISURFACE (POLYGON ((545...
#> 3     14.483235 1.96871269 MULTISURFACE (POLYGON ((546...
#> 4      7.833991 0.44711025 MULTISURFACE (POLYGON ((554...
#> 5      5.317382 0.14865743 MULTISURFACE (POLYGON ((347...
#> 6      7.775258 0.09235785 MULTISURFACE (POLYGON ((436...
#> 7     57.802492 4.44599957 MULTISURFACE (POLYGON ((392...
#> 8      6.927052 0.21110027 MULTISURFACE (POLYGON ((372...
#> 9      5.069516 0.28414194 MULTISURFACE (POLYGON ((373...
#> 10     6.074958 0.36432273 MULTISURFACE (POLYGON ((421...

To request a range we can use filter functions between and and.

emodnet_get_layers(wfs = wfs_gs, layers = "seabed_substrate_1m",
                       cql_filter = "shape_length between 2 and 4",
                       reduce_layers = TRUE )
#> Simple feature collection with 769 features and 30 fields
#> Geometry type: MULTISURFACE
#> Dimension:     XY
#> Bounding box:  xmin: 879101 ymin: 515053.8 xmax: 7670427 ymax: 6538870
#> Projected CRS: ETRS89-extended / LCC Europe
#> First 10 features:
#>                       gml_id    id objectid   code  country  data_holder
#> 1    seabed_substrate_1m.108   108      108 BG-001 Bulgaria IO-BAS, MOEW
#> 2   seabed_substrate_1m.1338  1338     1338 DK-001  Denmark         GEUS
#> 3   seabed_substrate_1m.5779  5779     5779 ES-008    Spain         IGME
#> 4     seabed_substrate_1m.65    65       65 BG-001 Bulgaria IO-BAS, MOEW
#> 5     seabed_substrate_1m.66    66       66 BG-001 Bulgaria IO-BAS, MOEW
#> 6    seabed_substrate_1m.101   101      101 BG-001 Bulgaria IO-BAS, MOEW
#> 7    seabed_substrate_1m.103   103      103 BG-001 Bulgaria IO-BAS, MOEW
#> 8    seabed_substrate_1m.106   106      106 BG-001 Bulgaria IO-BAS, MOEW
#> 9   seabed_substrate_1m.7887  7887     7887 FI-008  Finland          GTK
#> 10 seabed_substrate_1m.10827 10827    10827 FO-002   Faroes         FEED
#>                   contact   scale original_scale      original_grain_size
#> 1          geos@io-bas.bg 1000000              0               BNS-676.85
#> 2             jol@geus.dk 1000000              0               Folk_4\r\n
#> 3     t.medialdea@igme.es 1000000              0                     Folk
#> 4          geos@io-bas.bg 1000000              0               BNS-676.85
#> 5          geos@io-bas.bg 1000000              0               BNS-676.85
#> 6          geos@io-bas.bg 1000000              0               BNS-676.85
#> 7          geos@io-bas.bg 1000000              0               BNS-676.85
#> 8          geos@io-bas.bg 1000000              0               BNS-676.85
#> 9  jyrki.rantataro@gtk.fi 1000000              0  Finnish GEO –class 1974
#> 10               bh@jf.fo 1000000              0 Faroese GEM Network 2001
#>                                                                                                                                                                              references
#> 1                                                                            Kojuharov et al., 2009, Geological map of Seabed sediments of Bulgarian EEZ in scale 1:500000, Sofia, MOEW
#> 2                                                                                         Stevenson et al., 2011. EMODnet Geol. Proj. Draft Final Rep. Prep. Actions for EMODnet. Lot 2
#> 3                             Mapa Geológico de la Plataforma Continental Española. Hojas 41-42 (Tortosa-Tarragona).Escala 1:200.000. 1986. Instituto Geológico y Minero de España,IGME
#> 4                                                                            Kojuharov et al., 2009, Geological map of Seabed sediments of Bulgarian EEZ in scale 1:500000, Sofia, MOEW
#> 5                                                                            Kojuharov et al., 2009, Geological map of Seabed sediments of Bulgarian EEZ in scale 1:500000, Sofia, MOEW
#> 6                                                                            Kojuharov et al., 2009, Geological map of Seabed sediments of Bulgarian EEZ in scale 1:500000, Sofia, MOEW
#> 7                                                                            Kojuharov et al., 2009, Geological map of Seabed sediments of Bulgarian EEZ in scale 1:500000, Sofia, MOEW
#> 8                                                                            Kojuharov et al., 2009, Geological map of Seabed sediments of Bulgarian EEZ in scale 1:500000, Sofia, MOEW
#> 9                                                                                                          Marine Geological mapping programme of Finland/Geological Survey of Finland.
#> 10 Ritchie D., Ziska H., Johnson H., Evans D., eds., Geology of the Faroe-Shetland Basin and adjacent areas: Nottingham, UK, British Geological Survey Research Report RR/11/01, 317 p.
#>                                                                                                                                                  comments
#> 1                                                                                                                                             Public data
#> 2                                               Generalized from 250k scale to 1 M by GTK June 2016/EMODnet Geology. Compiled from several national maps.
#> 3                                                                                                                                                        
#> 4                                                                                                                                             Public data
#> 5                                                                                                                                             Public data
#> 6                                                                                                                                             Public data
#> 7                                                                                                                                             Public data
#> 8                                                                                                                                             Public data
#> 9  Generalized from 250k scale to 1 M by GTK June 2016/EMODnet Geology. Ongoing mapping programme. Generalized to 1:250 000. Original data is restricted.
#> 10                                                                                     Deep-water fine to medium-grained sand and mud with gravel patches
#>    reclassification method sample_number
#> 1                 2      4             0
#> 2                 2      4             0
#> 3                 2      3             0
#> 4                 2      4             0
#> 5                 2      4             0
#> 6                 2      4             0
#> 7                 2      4             0
#> 8                 2      4             0
#> 9                 2      4             0
#> 10                2      2            36
#>                                    original_substrate relation folk_16cl
#> 1         Undefined coastal sands, rocks and boulders        5         6
#> 2                                                            0         6
#> 3                                          muddy Sand        1         6
#> 4               Local Lithostratigraphyc unit Ia-clay        5         6
#> 5               Local Lithostratigraphyc unit Ia-clay        5         6
#> 6                     Local Lithostratigraphyc unit O        5         6
#> 7         Undefined coastal sands, rocks and boulders        5         6
#> 8         Undefined coastal sands, rocks and boulders        5         6
#> 9                                                            0         6
#> 10 Fine-medium grained sand & mud with gravel patches        2       132
#>                 folk_16cl_txt folk_7cl                folk_7cl_txt folk_5cl
#> 1    6. No data at this level        2                     2. Sand        2
#> 2    6. No data at this level        4           4. Mixed sediment        4
#> 3    6. No data at this level       13              13. muddy Sand        1
#> 4    6. No data at this level       11                    11. Mud         1
#> 5    6. No data at this level       11                    11. Mud         1
#> 6    6. No data at this level        3 3. Coarse-grained sediment         3
#> 7    6. No data at this level        2                     2. Sand        2
#> 8    6. No data at this level        2                     2. Sand        2
#> 9    6. No data at this level        4           4. Mixed sediment        4
#> 10 132. (gravelly) muddy Sand       13              13. muddy Sand        1
#>                   folk_5cl_txt surface_feature conf_rs conf_s conf_d conf_tot
#> 1                     2. Sand                       NA     NA     NA       NA
#> 2            4. Mixed sediment                      NA     NA     NA       NA
#> 3         1. Mud to muddy Sand                      NA     NA     NA       NA
#> 4         1. Mud to muddy Sand                      NA     NA     NA       NA
#> 5         1. Mud to muddy Sand                      NA     NA     NA       NA
#> 6  3. Coarse-grained sediment                       NA     NA     NA       NA
#> 7                     2. Sand                       NA     NA     NA       NA
#> 8                     2. Sand                       NA     NA     NA       NA
#> 9            4. Mixed sediment                      NA     NA     NA       NA
#> 10        1. Mud to muddy Sand                      NA     NA     NA       NA
#>    shape_length shape_area                           geom
#> 1      2.629942 0.01482684 MULTISURFACE (POLYGON ((540...
#> 2      2.360505 0.02975574 MULTISURFACE (POLYGON ((405...
#> 3      2.482162 0.02442064 MULTISURFACE (POLYGON ((334...
#> 4      2.528585 0.11428307 MULTISURFACE (POLYGON ((553...
#> 5      3.640578 0.09411611 MULTISURFACE (POLYGON ((548...
#> 6      3.898868 0.23404166 MULTISURFACE (POLYGON ((545...
#> 7      2.475150 0.02201476 MULTISURFACE (POLYGON ((543...
#> 8      3.332369 0.03188266 MULTISURFACE (POLYGON ((539...
#> 9      2.108103 0.05114040 MULTISURFACE (POLYGON ((459...
#> 10     2.686485 0.17193173 MULTISURFACE (POLYGON ((323...

Filtering with spatial predicates

Another powerful option for filtering features is by using spatial predicates

For example, we could use the ECQL spatial predicate BBOX() to request only features that intersect a defined bounding box. Note that geom is the name of the attribute that contains feature geometries, coordinates are supplied in the sequence xmin, xmax, ymin, ymax and the query default is to use the CRS of the queried layer unless an additional CRS argument is provided.

bbox_filter <- emodnet_get_layers(wfs = wfs_gs, layers = "seabed_substrate_1m",
                       cql_filter = "BBOX(geom, 2565427, 4026324, 1522239, 2778536)",
                       reduce_layers = TRUE ) 

map <- bbox_filter %>% 
    sf::st_cast(to = "GEOMETRYCOLLECTION") %>% 
    sf::st_collection_extract(type = "POLYGON") %>%
mapview::mapview(zcol = "folk_7cl_txt", burst = TRUE)

map

Using OR and AND statements

Filter conditions can also be a logical combination of other conditions using AND, OR or NOT. We showed previously how we could use a list of potential values to match an attribute to. This could also be achieved using an OR statement.

For example, the following query returns features where country is either Baltic Sea or Bulgaria.

emodnet_get_layers(wfs = wfs_gs, layers = "seabed_substrate_1m",
                       cql_filter = "country='Baltic Sea' OR country='Bulgaria'",
                   reduce_layers = TRUE )
#> Simple feature collection with 63 features and 30 fields
#> Geometry type: MULTISURFACE
#> Dimension:     XY
#> Bounding box:  xmin: 4486837 ymin: 1897776 xmax: 5658431 ymax: 3690069
#> Projected CRS: ETRS89-extended / LCC Europe
#> First 10 features:
#>                    gml_id id objectid   code  country  data_holder
#> 1  seabed_substrate_1m.68 68       68 BG-001 Bulgaria IO-BAS, MOEW
#> 2  seabed_substrate_1m.97 97       97 BG-001 Bulgaria IO-BAS, MOEW
#> 3  seabed_substrate_1m.47 47       47 BG-001 Bulgaria IO-BAS, MOEW
#> 4  seabed_substrate_1m.48 48       48 BG-001 Bulgaria IO-BAS, MOEW
#> 5  seabed_substrate_1m.49 49       49 BG-001 Bulgaria IO-BAS, MOEW
#> 6  seabed_substrate_1m.50 50       50 BG-001 Bulgaria IO-BAS, MOEW
#> 7  seabed_substrate_1m.51 51       51 BG-001 Bulgaria IO-BAS, MOEW
#> 8  seabed_substrate_1m.52 52       52 BG-001 Bulgaria IO-BAS, MOEW
#> 9  seabed_substrate_1m.53 53       53 BG-001 Bulgaria IO-BAS, MOEW
#> 10 seabed_substrate_1m.54 54       54 BG-001 Bulgaria IO-BAS, MOEW
#>           contact   scale original_scale original_grain_size
#> 1  geos@io-bas.bg 1000000              0          BNS-676.85
#> 2  geos@io-bas.bg 1000000              0          BNS-676.85
#> 3  geos@io-bas.bg 1000000              0          BNS-676.85
#> 4  geos@io-bas.bg 1000000              0          BNS-676.85
#> 5  geos@io-bas.bg 1000000              0          BNS-676.85
#> 6  geos@io-bas.bg 1000000              0          BNS-676.85
#> 7  geos@io-bas.bg 1000000              0          BNS-676.85
#> 8  geos@io-bas.bg 1000000              0          BNS-676.85
#> 9  geos@io-bas.bg 1000000              0          BNS-676.85
#> 10 geos@io-bas.bg 1000000              0          BNS-676.85
#>                                                                                                    references
#> 1  Kojuharov et al., 2009, Geological map of Seabed sediments of Bulgarian EEZ in scale 1:500000, Sofia, MOEW
#> 2  Kojuharov et al., 2009, Geological map of Seabed sediments of Bulgarian EEZ in scale 1:500000, Sofia, MOEW
#> 3  Kojuharov et al., 2009, Geological map of Seabed sediments of Bulgarian EEZ in scale 1:500000, Sofia, MOEW
#> 4  Kojuharov et al., 2009, Geological map of Seabed sediments of Bulgarian EEZ in scale 1:500000, Sofia, MOEW
#> 5  Kojuharov et al., 2009, Geological map of Seabed sediments of Bulgarian EEZ in scale 1:500000, Sofia, MOEW
#> 6  Kojuharov et al., 2009, Geological map of Seabed sediments of Bulgarian EEZ in scale 1:500000, Sofia, MOEW
#> 7  Kojuharov et al., 2009, Geological map of Seabed sediments of Bulgarian EEZ in scale 1:500000, Sofia, MOEW
#> 8  Kojuharov et al., 2009, Geological map of Seabed sediments of Bulgarian EEZ in scale 1:500000, Sofia, MOEW
#> 9  Kojuharov et al., 2009, Geological map of Seabed sediments of Bulgarian EEZ in scale 1:500000, Sofia, MOEW
#> 10 Kojuharov et al., 2009, Geological map of Seabed sediments of Bulgarian EEZ in scale 1:500000, Sofia, MOEW
#>       comments reclassification method sample_number
#> 1  Public data                2      4             0
#> 2  Public data                2      4             0
#> 3  Public data                2      4             0
#> 4  Public data                2      4             0
#> 5  Public data                2      4             0
#> 6  Public data                2      4             0
#> 7  Public data                2      4             0
#> 8  Public data                2      4             0
#> 9  Public data                2      4             0
#> 10 Public data                2      4             0
#>                          original_substrate relation folk_16cl
#> 1     Local Lithostratigraphyc unit Ia-clay        5         6
#> 2           Local Lithostratigraphyc unit O        5         6
#> 3         Local Lithostratigraphyc unit A-D        5         6
#> 4         Local Lithostratigraphyc unit A-D        5         6
#> 5  Local Lithostratigraphyc unit Ia-breccia        5         6
#> 6  Local Lithostratigraphyc unit Ia-breccia        5         6
#> 7  Local Lithostratigraphyc unit Ia-breccia        5         6
#> 8  Local Lithostratigraphyc unit Ia-breccia        5         6
#> 9  Local Lithostratigraphyc unit Ia-breccia        5         6
#> 10 Local Lithostratigraphyc unit Ia-breccia        5         6
#>               folk_16cl_txt folk_7cl                folk_7cl_txt folk_5cl
#> 1  6. No data at this level       11                    11. Mud         1
#> 2  6. No data at this level        3 3. Coarse-grained sediment         3
#> 3  6. No data at this level       11                    11. Mud         1
#> 4  6. No data at this level       11                    11. Mud         1
#> 5  6. No data at this level        4           4. Mixed sediment        4
#> 6  6. No data at this level        4           4. Mixed sediment        4
#> 7  6. No data at this level        4           4. Mixed sediment        4
#> 8  6. No data at this level        4           4. Mixed sediment        4
#> 9  6. No data at this level        4           4. Mixed sediment        4
#> 10 6. No data at this level        4           4. Mixed sediment        4
#>                   folk_5cl_txt surface_feature conf_rs conf_s conf_d conf_tot
#> 1         1. Mud to muddy Sand                      NA     NA     NA       NA
#> 2  3. Coarse-grained sediment                       NA     NA     NA       NA
#> 3         1. Mud to muddy Sand                      NA     NA     NA       NA
#> 4         1. Mud to muddy Sand                      NA     NA     NA       NA
#> 5            4. Mixed sediment                      NA     NA     NA       NA
#> 6            4. Mixed sediment                      NA     NA     NA       NA
#> 7            4. Mixed sediment                      NA     NA     NA       NA
#> 8            4. Mixed sediment                      NA     NA     NA       NA
#> 9            4. Mixed sediment                      NA     NA     NA       NA
#> 10           4. Mixed sediment                      NA     NA     NA       NA
#>    shape_length   shape_area                           geom
#> 1    0.01060621 2.086318e-06 MULTISURFACE (POLYGON ((553...
#> 2    0.07127202 3.086508e-04 MULTISURFACE (POLYGON ((545...
#> 3    0.26086513 3.312509e-03 MULTISURFACE (POLYGON ((546...
#> 4    7.37818075 5.673158e-01 MULTISURFACE (POLYGON ((545...
#> 5    0.18288563 1.358180e-03 MULTISURFACE (POLYGON ((548...
#> 6    0.07400996 1.980726e-04 MULTISURFACE (POLYGON ((548...
#> 7    0.64075727 1.952430e-02 MULTISURFACE (POLYGON ((549...
#> 8    0.76062575 3.213083e-02 MULTISURFACE (POLYGON ((554...
#> 9    0.62084292 2.365798e-02 MULTISURFACE (POLYGON ((551...
#> 10   0.20715594 2.148920e-03 MULTISURFACE (POLYGON ((548...

Let’s say we also want to restrict the features returned those having shape_length > 1. We can include an additional condition which must be met using an AND statement.


filter_sf1 <- emodnet_get_layers(wfs = wfs_gs, layers = "seabed_substrate_1m",
                       cql_filter = "country='Baltic Sea' OR country='Bulgaria' AND shape_length>1",
                       reduce_layers = TRUE )
filter_sf1
#> Simple feature collection with 14 features and 30 fields
#> Geometry type: MULTISURFACE
#> Dimension:     XY
#> Bounding box:  xmin: 4486837 ymin: 1897776 xmax: 5658431 ymax: 3690069
#> Projected CRS: ETRS89-extended / LCC Europe
#> First 10 features:
#>                     gml_id  id objectid   code  country  data_holder
#> 1   seabed_substrate_1m.48  48       48 BG-001 Bulgaria IO-BAS, MOEW
#> 2  seabed_substrate_1m.108 108      108 BG-001 Bulgaria IO-BAS, MOEW
#> 3   seabed_substrate_1m.56  56       56 BG-001 Bulgaria IO-BAS, MOEW
#> 4   seabed_substrate_1m.60  60       60 BG-001 Bulgaria IO-BAS, MOEW
#> 5   seabed_substrate_1m.61  61       61 BG-001 Bulgaria IO-BAS, MOEW
#> 6   seabed_substrate_1m.64  64       64 BG-001 Bulgaria IO-BAS, MOEW
#> 7   seabed_substrate_1m.65  65       65 BG-001 Bulgaria IO-BAS, MOEW
#> 8   seabed_substrate_1m.69  69       69 BG-001 Bulgaria IO-BAS, MOEW
#> 9   seabed_substrate_1m.66  66       66 BG-001 Bulgaria IO-BAS, MOEW
#> 10  seabed_substrate_1m.91  91       91 BG-001 Bulgaria IO-BAS, MOEW
#>           contact   scale original_scale original_grain_size
#> 1  geos@io-bas.bg 1000000              0          BNS-676.85
#> 2  geos@io-bas.bg 1000000              0          BNS-676.85
#> 3  geos@io-bas.bg 1000000              0          BNS-676.85
#> 4  geos@io-bas.bg 1000000              0          BNS-676.85
#> 5  geos@io-bas.bg 1000000              0          BNS-676.85
#> 6  geos@io-bas.bg 1000000              0          BNS-676.85
#> 7  geos@io-bas.bg 1000000              0          BNS-676.85
#> 8  geos@io-bas.bg 1000000              0          BNS-676.85
#> 9  geos@io-bas.bg 1000000              0          BNS-676.85
#> 10 geos@io-bas.bg 1000000              0          BNS-676.85
#>                                                                                                    references
#> 1  Kojuharov et al., 2009, Geological map of Seabed sediments of Bulgarian EEZ in scale 1:500000, Sofia, MOEW
#> 2  Kojuharov et al., 2009, Geological map of Seabed sediments of Bulgarian EEZ in scale 1:500000, Sofia, MOEW
#> 3  Kojuharov et al., 2009, Geological map of Seabed sediments of Bulgarian EEZ in scale 1:500000, Sofia, MOEW
#> 4  Kojuharov et al., 2009, Geological map of Seabed sediments of Bulgarian EEZ in scale 1:500000, Sofia, MOEW
#> 5  Kojuharov et al., 2009, Geological map of Seabed sediments of Bulgarian EEZ in scale 1:500000, Sofia, MOEW
#> 6  Kojuharov et al., 2009, Geological map of Seabed sediments of Bulgarian EEZ in scale 1:500000, Sofia, MOEW
#> 7  Kojuharov et al., 2009, Geological map of Seabed sediments of Bulgarian EEZ in scale 1:500000, Sofia, MOEW
#> 8  Kojuharov et al., 2009, Geological map of Seabed sediments of Bulgarian EEZ in scale 1:500000, Sofia, MOEW
#> 9  Kojuharov et al., 2009, Geological map of Seabed sediments of Bulgarian EEZ in scale 1:500000, Sofia, MOEW
#> 10 Kojuharov et al., 2009, Geological map of Seabed sediments of Bulgarian EEZ in scale 1:500000, Sofia, MOEW
#>       comments reclassification method sample_number
#> 1  Public data                2      4             0
#> 2  Public data                2      4             0
#> 3  Public data                2      4             0
#> 4  Public data                2      4             0
#> 5  Public data                2      4             0
#> 6  Public data                2      4             0
#> 7  Public data                2      4             0
#> 8  Public data                2      4             0
#> 9  Public data                2      4             0
#> 10 Public data                2      4             0
#>                                    original_substrate relation folk_16cl
#> 1                   Local Lithostratigraphyc unit A-D        5         6
#> 2         Undefined coastal sands, rocks and boulders        5         6
#> 3            Local Lithostratigraphyc unit Ia-breccia        5         6
#> 4  Local Lithostratigraphyc unit Ia-carbonate-biogeni        5         6
#> 5               Local Lithostratigraphyc unit Ia-clay        5         6
#> 6               Local Lithostratigraphyc unit Ia-clay        5         6
#> 7               Local Lithostratigraphyc unit Ia-clay        5         6
#> 8               Local Lithostratigraphyc unit Ia-clay        5         6
#> 9               Local Lithostratigraphyc unit Ia-clay        5         6
#> 10                  Local Lithostratigraphyc unit K-H        5         6
#>               folk_16cl_txt folk_7cl      folk_7cl_txt folk_5cl
#> 1  6. No data at this level       11          11. Mud         1
#> 2  6. No data at this level        2           2. Sand        2
#> 3  6. No data at this level        4 4. Mixed sediment        4
#> 4  6. No data at this level       11          11. Mud         1
#> 5  6. No data at this level       11          11. Mud         1
#> 6  6. No data at this level       11          11. Mud         1
#> 7  6. No data at this level       11          11. Mud         1
#> 8  6. No data at this level       11          11. Mud         1
#> 9  6. No data at this level       11          11. Mud         1
#> 10 6. No data at this level       11          11. Mud         1
#>            folk_5cl_txt surface_feature conf_rs conf_s conf_d conf_tot
#> 1  1. Mud to muddy Sand                      NA     NA     NA       NA
#> 2              2. Sand                       NA     NA     NA       NA
#> 3     4. Mixed sediment                      NA     NA     NA       NA
#> 4  1. Mud to muddy Sand                      NA     NA     NA       NA
#> 5  1. Mud to muddy Sand                      NA     NA     NA       NA
#> 6  1. Mud to muddy Sand                      NA     NA     NA       NA
#> 7  1. Mud to muddy Sand                      NA     NA     NA       NA
#> 8  1. Mud to muddy Sand                      NA     NA     NA       NA
#> 9  1. Mud to muddy Sand                      NA     NA     NA       NA
#> 10 1. Mud to muddy Sand                      NA     NA     NA       NA
#>    shape_length shape_area                           geom
#> 1      7.378181 0.56731575 MULTISURFACE (POLYGON ((545...
#> 2      2.629942 0.01482684 MULTISURFACE (POLYGON ((540...
#> 3      1.155024 0.07369632 MULTISURFACE (POLYGON ((550...
#> 4     14.483235 1.96871269 MULTISURFACE (POLYGON ((546...
#> 5      1.425905 0.04474783 MULTISURFACE (POLYGON ((546...
#> 6      1.956767 0.06223765 MULTISURFACE (POLYGON ((561...
#> 7      2.528585 0.11428307 MULTISURFACE (POLYGON ((553...
#> 8      1.856806 0.02172805 MULTISURFACE (POLYGON ((553...
#> 9      3.640578 0.09411611 MULTISURFACE (POLYGON ((548...
#> 10     7.833991 0.44711025 MULTISURFACE (POLYGON ((554...

The query returns features where country is Baltic Sea or Bulgaria but we can see that the minimum value is below the minimum we set with our filter. That’s because the AND filter is added only to the country='Bulgaria', so while only features with shape_length > 1 are returned where country is also Bulgaria, the filter is not applied to shape_length where country is Baltic Sea.

unique(filter_sf1$country)
#> [1] "Bulgaria"   "Baltic Sea"

min(filter_sf1$shape_length)
#> [1] 0.2962585

To add the AND filter to both OR filters, we can use a parenthesis:

filter_sf2 <- emodnet_get_layers(wfs = wfs_gs, layers = "seabed_substrate_1m",
                       cql_filter = "(country='Baltic Sea' OR country='Bulgaria') AND shape_length>1",
                       reduce_layers = TRUE )

Now the minimum value is indeed above 1. However, we only get features where country is 'Bulgaria'. That’s because the single Baltic Sea feature had a shape_length value smaller than 1 so is filtered out.


min(filter_sf2$shape_length)
#> [1] 1.155024
unique(filter_sf2$country)
#> [1] "Bulgaria"

Finally filtering for shape_length < 1 returns features with shape_length values smaller than 1 for both country values.

filter_sf3 <- emodnet_get_layers(wfs = wfs_gs, layers = "seabed_substrate_1m",
                       cql_filter = "(country='Baltic Sea' OR country='Bulgaria') AND shape_length<1",
                       reduce_layers = TRUE )
max(filter_sf3$shape_length)
#> [1] 0.7606257
unique(filter_sf3$country)
#> [1] "Bulgaria"   "Baltic Sea"

Advanced use

There is more that can accomplished by using the EMODnet WFS services than downloading data. The EMODnetWFS package is built on top of the ows4R library, meaning that all the functionalities of this package are available for EMODnetWFS. The ows4R returns a special type of R object called R6. You can learn more in Hadley Wickham’s chapter on R6 Objects of the Advance R book.

For instance: it is not efficient to read a large dataset into R just and later subset part of it. This requires longer waiting times and more bandwidth usage, and in very large datasets it would simply not be possible. For instance, all the occurrences data available through the EMODnet Biology portal are stored in one table: These are approximately 30 millions rows! In this case, we suggest you access the EMODnet Biology occurrence data through the download toolbox or the eurobis R package instead.